using System;
using System.Reflection;
using CriticalSystems.Instrumentation.Internal;

namespace CriticalSystems.Instrumentation
{
    public static class Logging
    {
        public static void In()
        {
            string method;
            GetLog(out method).In(method);
        }

        public static void Out()
        {
            string method;
            GetLog(out method).Out(method);
        }

        public static void Out(Exception ex)
        {
            string method;
            GetLog(out method).Out(method, ex);
        }

        public static void Info(string text, params object[] parameters)
        {
            string method;
            GetLog(out method).Info(method, text, parameters);
        }

        public static void Warning(string text, params object[] parameters)
        {
            string method;
            GetLog(out method).Warning(method, text, parameters);
        }

        public static void Error(string text, params object[] parameters)
        {
            string method;
            GetLog(out method).Error(method, text, parameters);
        }

        public static void Error(Exception ex)
        {
            string method;
            GetLog(out method).Error(method, ex);
        }

        private static Log GetLog(out string method)
        {
            MethodBase callingMethod = ReflectionHelper.GetCallingMethod();
            method = callingMethod.Name;
            return new Log(callingMethod.DeclaringType.Assembly.GetName().Name, callingMethod.DeclaringType.FullName);
        }

    }
}